package com.sneaker.shower.entity.domain.order;

import com.baomidou.mybatisplus.annotation.FieldStrategy;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.sneaker.shower.entity.domain.BaseUserDomain;
import com.sneaker.shower.entity.enums.SubOrderStatusEnum;
import lombok.*;
import org.springframework.util.Base64Utils;

import java.math.BigDecimal;

@EqualsAndHashCode(callSuper = true)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TableName("sub_order")
public class SubOrderDO extends BaseUserDomain {

    /**
     * 结账订单guid
     */
    private Long payOrderGuid;

    /**
     * 订单名字
     */
    private String orderName;

    /**
     * 订单图片
     */
    private String imageUrl;

    /**
     * 产品名字拼接后字符串
     */
    private String productName;

    /**
     * 订单数量
     */

    private Integer orderCount = 1;

    /**
     * 是否在购物车（如果在购物车 则说明还未下单 则在我的订单不展示）
     */
    private Boolean isInCart = Boolean.FALSE;

    /**
     * 购物车guid
     */
    @TableField(strategy = FieldStrategy.IGNORED)
    private Long cartGuid;

    /**
     * 是否审核
     */
    private Boolean isChecked = false;

    /**
     * 订单原价
     */
    private BigDecimal orderPrice = BigDecimal.ZERO;

    /**
     * 订单折扣
     */
    private BigDecimal discount = BigDecimal.ONE;

    /**
     * 应付金额
     */
    private BigDecimal totalFee = BigDecimal.ZERO;

    /**
     * 消费会员卡金额
     */
    private BigDecimal cardFee = BigDecimal.ZERO;

    /**
     * 消费的哪张卡 方便支付失败的时候把金额退回到这张卡上
     */
    private Long userLevelGuid;

    /**
     * 实际支付金额
     */
    private BigDecimal actuallyPayFee = BigDecimal.ZERO;

    /**
     * 优惠总金额
     */
    private BigDecimal totalDiscountFee;

    private Byte status = SubOrderStatusEnum.WAIT_FOR_SUBMITTING.getCode();

    /**
     * 图片1
     */
    private String img1;

    /**
     * 图片2
     */
    private String img2;

    /**
     * 图片3
     */
    private String img3;

    /**
     * 图片4
     */
    private String img4;

    /**
     * 图片5
     */
    private String img5;

    /**
     * 图片6
     */
    private String img6;

    /**
     * 备注
     */
    private String remark;

    /**
     * 快递单号
     */
    private String trackingNumber;

    /**
     * 用户快递的公司ID
     */
    private String deliveryId;

    /**
     * 客服寄出的快递单号
     */
    private String sysTrackingNumber;

    /**
     * 客服快递的公司ID
     */
    private String sysDeliveryId;

    private String receiveInfoGuid;

    private Long couponGuid;

    private Boolean usedCoupon;

    private Integer version;

    public String getRemark() {
        String base64Pattern = "^([A-Za-z0-9+/]{4})*([A-Za-z0-9+/]{4}|[A-Za-z0-9+/]{3}=|[A-Za-z0-9+/]{2}==)$";
        return this.remark == null ? "" : this.remark.matches(base64Pattern) ? new String(Base64Utils.decodeFromString(this.remark)) : this.remark;
    }

    public void setRemark(String remark) {
        this.remark = remark == null ? null : Base64Utils.encodeToString(remark.getBytes());
    }
}
